package com.zh.freechat.domain.user.entity;

/**
 * @author Zhou
 * @date 14:02 2025/7/18
 */

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zh.webcommon.common.auditor.mp.SimpleEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Objects;

/**
 * 用户的好友关系
 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName(value = "ch_user_friend")
public  class UserRelationFriend extends SimpleEntity {
    /**
     * ID
     */
    @TableId(type = IdType.AUTO)
    protected Long id;

    private String user1;

    private String user2;
    /**
     * 备注名
     */
    private String aliasName;

    /**
     * user1清除标记
     */
    private boolean removed_u1;
    /**
     * user2清除标记
     */
    private boolean removed_u2;

    private int version;

    /**
     * 好友用户关联实体
     */
    @TableField(exist = false)
    private ChatUser chatUser;

    protected UserRelationFriend() {
    }

    public UserRelationFriend(String userId1, String userId2) {
        if (userId1.compareTo(userId2) < 0) {
            this.user1 = userId1;
            this.user2 = userId2;
        } else {
            this.user1 = userId2;
            this.user2 = userId1;
        }
    }

    public String getFriendId(String selfUserId) {
        return Objects.equals(selfUserId, this.user1) ? this.user2 : this.user1;
    }

}

